package com.yxinsur.imc.web.controller.business;

import com.yxinsur.imc.business.form.PrerenewalCreateForm;
import com.yxinsur.imc.business.form.PrerenewalDetailForm;
import com.yxinsur.imc.business.form.PrerenewalForm;
import com.yxinsur.imc.business.form.RealConfirmForm;
import com.yxinsur.imc.business.service.IImcPrerenewalDetailService;
import com.yxinsur.imc.business.service.IImcPrerenewalService;
import com.yxinsur.imc.business.vo.PrerenewalDetailVo;
import com.yxinsur.imc.business.vo.PrerenewalVo;
import com.yxinsur.imc.business.vo.RealConfirmVo;
import com.yxinsur.imc.common.annotation.Log;
import com.yxinsur.imc.common.core.controller.BaseController;
import com.yxinsur.imc.common.core.domain.AjaxResult;
import com.yxinsur.imc.common.core.page.TableDataInfo;
import com.yxinsur.imc.common.enums.BusinessType;
import com.yxinsur.imc.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 待导入续期主Controller
 *
 * @author imc
 * @date 2021-05-26
 */
@Api(value = "续期管理模块接口服务", tags = {"10.续期管理模块接口服务"})
@RestController
@RequestMapping("/business/prerenewal")
public class ImcPrerenewalController extends BaseController {
    @Autowired
    private IImcPrerenewalService imcPrerenewalService;
    @Autowired
    private IImcPrerenewalDetailService imcPrerenewalDetailService;

    /**
     * 查询待导入续期主列表
     */
    @ApiOperation("续期抽档分页数据查询")
    @GetMapping("/list")
    public TableDataInfo list(PrerenewalForm prerenewalForm) {
        startPage();
        List<PrerenewalVo> list = imcPrerenewalService.selectImcPrerenewalList(prerenewalForm);
        return getDataTable(list);
    }

    /**
     * 生成续期数据
     */
    @ApiOperation("生成续期数据")
    @Log(title = "生成续期数据", businessType = BusinessType.INSERT)
    @PostMapping("/create")
    public AjaxResult create(@RequestBody PrerenewalCreateForm prerenewalCreateForm) {
        int count = this.imcPrerenewalService.createPrerenewalData(prerenewalCreateForm);
        return AjaxResult.success("续期数据生成成功，生成" + count + "条续期数据");
    }

    /**
     * 查询待导入续期主列表
     */
    @ApiOperation("批次详情列表分页数据")
    @GetMapping("/detail/list")
    public TableDataInfo detailList(PrerenewalDetailForm prerenewalDetailForm) {
        startPage();
        List<PrerenewalDetailVo> list = imcPrerenewalDetailService.selectImcPrerenewalDetailList(prerenewalDetailForm);
        return getDataTable(list);
    }

    /**
     * 导出续期详情列表
     */
    @ApiOperation("保批次详情列表导出")
    @GetMapping("/detail/export")
    public AjaxResult export(PrerenewalDetailForm prerenewalDetailForm) {
        List<PrerenewalDetailVo> list = imcPrerenewalDetailService.selectImcPrerenewalDetailList(prerenewalDetailForm);
        ExcelUtil<PrerenewalDetailVo> util = new ExcelUtil<PrerenewalDetailVo>(PrerenewalDetailVo.class);
        return util.exportExcel(list, "续期详情列表数据");
    }

    /**
     * 续期详情批量删除
     */
    @ApiOperation("续期详情批量删除")
    @DeleteMapping("/detail/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(imcPrerenewalDetailService.deleteImcPrerenewalDetailByIds(ids));
    }

    /**
     * 确认导入
     */
    @ApiOperation("确认导入")
    @PostMapping("/confirm/{id}")
    public AjaxResult confirm(@PathVariable("id") Long id) {
        int count = this.imcPrerenewalService.confirmImportData(id);
        return AjaxResult.success("确认导入操作成功，导入该批次下" + count + "条续期数据");
    }

    /**
     * 撤销导入
     */
    @ApiOperation("撤销导入")
    @PostMapping("/cancel/{id}")
    public AjaxResult cancel(@PathVariable("id") Long id) {
        int count = this.imcPrerenewalService.cancelConfirm(id);
        return AjaxResult.success("撤销操作成功，撤销该批次下" + count + "条续期数据");
    }

    /**
     * 删除批次
     */
    @ApiOperation("删除批次")
    @PostMapping("/remove/{id}")
    public AjaxResult remove(@PathVariable("id") Long id) {
        int count = this.imcPrerenewalService.removeData(id);
        return AjaxResult.success("删除操作成功");
    }

    /**
     * 实收确认
     */
    @ApiOperation("实收确认")
    @PostMapping("/realConfirm")
    public AjaxResult realConfirm(@RequestBody RealConfirmForm realConfirmForm) {
           return toAjax(this.imcPrerenewalService.realConfirm(realConfirmForm));
    }

    /**
     * 实收获取费率
     */
    @ApiOperation("实收获取费率")
    @PostMapping("/realGetRates")
    public AjaxResult realGetRates(@RequestBody RealConfirmForm realConfirmForm) {
        RealConfirmVo vo = this.imcPrerenewalService.realGetRates(realConfirmForm);
        return AjaxResult.success(vo);
    }
}
